﻿using System;
using System.Collections.Generic;
using System.Text;

namespace skydream
{

        public class OfficeControlDll
        {
            ///// <summary>
            ///// 把源表里选中的一行数据 加入到目的表里
            ///// 如果目的表的列多于源表的列，则目的表的多于列是可写的。
            ///// </summary>
            ///// <param name="dataGridSouce"> 源</param>
            ///// <param name="dataGridTarget">目标datagridview</param>
            //public static void AddDataGridView(DataGridView dataGridSouce, DataGridView dataGridTarget, params int[] isz)
            //{
            //    int dataSouceCellsCount = dataGridSouce.CurrentRow.Cells.Count;
            //    int dataTargetCellsCount = dataGridTarget.Columns.Count;
            //    string[] strDataSouce = new string[dataSouceCellsCount];
            //    if (isz.Length <= 0)
            //    {
            //        for (int i = 0; i < dataSouceCellsCount; i++)
            //        {
            //            string cellText = dataGridSouce.CurrentRow.Cells[i].Value.ToString();
            //            strDataSouce[i] = cellText;
            //        }
            //    }
            //    else
            //    {
            //        for (int i = 0; i < isz.Length; i++)
            //        {
            //            string cellText = dataGridSouce.CurrentRow.Cells[isz[i]].Value.ToString();
            //            strDataSouce[i] = cellText;
            //        }
            //    }
            //    dataGridTarget.Rows.Add(strDataSouce);
            //    for (int j = 0; j < dataSouceCellsCount; j++)
            //    {
            //        dataGridTarget.Columns[j].ReadOnly = true;
            //    }
            //    int dataGridTargetWrite = dataTargetCellsCount - dataSouceCellsCount;
            //    if (dataGridTargetWrite > 0)
            //    {
            //        for (int w = 0; w < dataGridTargetWrite; w++)
            //        {
            //            int canWriteIndex = dataSouceCellsCount + w;
            //            dataGridTarget.Columns[canWriteIndex].ReadOnly = false;
            //        }
            //    }
            //}

            ///// <summary>
            ///// 删除表中选中的一行
            ///// </summary>
            ///// <param name="dataView">表</param>
            //public static void DeleteRowDataGridView(DataGridView dataView)
            //{
            //    dataView.Rows.Remove(dataView.CurrentRow);
            //}

            ///// <summary>
            ///// 清除表中的所有内容
            ///// </summary>
            ///// <param name="dataView"></param>
            //public static void ClearDataGridView(DataGridView dataView)
            //{
            //    int count = dataView.Rows.Count;

            //    for (int i = 0; i < count; i++)
            //    {

            //        dataView.Rows.Remove(dataView.Rows[0]);
            //    }
            //}

            ///// <summary>
            ///// 表中的数据全部插入数据库
            ///// </summary>
            ///// <param name="dataView"></param>
            //public static void UpdateDataGridToDatabase(DataGridView dataView)
            //{

            //}

            ///// <summary>
            ///// 显示datagrid
            ///// </summary>
            ///// <param name="dataView"></param>
            ///// <param name="dt"></param>
            //public static void ShowDataGrid(DataGridView dataView, DataTable dt)
            //{
            //    dataView.DataSource = dt;


            //}
            ///// <summary>
            ///// combox 数据绑定
            ///// </summary>
            ///// <param name="cmbox"></param>
            ///// <param name="dt"></param>
            ///// <param name="itemsValue"></param>
            ///// <param name="itemsText"></param>
            //public static void ShowCombox(ComboBox cmbox, DataTable dt, string itemsValue, string itemsText)
            //{
            //    cmbox.DataSource = dt;
            //    cmbox.DisplayMember = itemsText;
            //    cmbox.ValueMember = itemsValue;

            //}
            ///// <summary>
            ///// 计算datagridview 中某一列的和        
            ///// </summary>
            ///// <param name="dt"></param>
            ///// <param name="columnsIndex"></param>
            ///// <returns></returns>
            //public static decimal DatagridColumnSum(DataGridView dt, string columnsName)
            //{
            //    decimal sum = 0;
            //    for (int rowIndex = 0; rowIndex < dt.Rows.Count; rowIndex++)
            //    {
            //        sum += Convert.ToDecimal(dt.Rows[rowIndex].Cells[columnsName].Value);
            //    }
            //    return sum;
            //}
            //public static bool ExportDataGridview(DataGridView gridView, bool isShowExcele, string bt)
            //{
            //    if (gridView.Rows.Count == 0)
            //    {
            //        return false;
            //    }
            //    Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
            //    excel.Application.Workbooks.Add(true);
            //    excel.Visible = isShowExcele;
            //    int rowCount = gridView.Rows.Count;
            //    int colCount = gridView.Columns.Count;
            //    object[,] dataArray = new object[rowCount + 1, colCount];
            //    for (int i = 0; i < gridView.ColumnCount; i++)
            //    {
            //        dataArray[0, i] = gridView.Columns[i].HeaderText;

            //    }
            //    for (int i = 0; i < rowCount; i++)
            //    {
            //        for (int j = 0; j < colCount; j++)
            //        {
            //            if (gridView[j, i].Value.GetType() == typeof(string))
            //            {
            //                dataArray[i + 1, j] = "'" + gridView[j, i].Value.ToString();
            //            }
            //            else
            //            {
            //                dataArray[i + 1, j] = gridView[j, i].Value.ToString();

            //            }
            //        }
            //    }
            //    int h = gridView.Columns.Count;
            //    int p = h / 2;




            //    int k = Convert.ToInt32('A');
            //    char r = Convert.ToChar(k + p);
            //    string s = r.ToString() + "1";
            //    //标题列
            //    excel.get_Range(s, System.Reflection.Missing.Value).Value2 = bt;
            //    //数据列
            //    excel.get_Range("A2", excel.Cells[rowCount + 2, colCount]).Value2 = dataArray;

            //    excel.Cells.EntireColumn.AutoFit();
            //    return true;


            //}

            //public static void OnlyShuzi(TextBox textbox, string pattern, ref string str)
            //{
            //    Match m = Regex.Match(textbox.Text, pattern);   // 匹配正则表达式

            //    if (!m.Success)   // 输入的不是数字
            //    {
            //        textbox.Text = str;   // textBox内容不变

            //        // 将光标定位到文本框的最后
            //        textbox.SelectionStart = textbox.Text.Length;
            //    }
            //    else   // 输入的是数字
            //    {
            //        str = textbox.Text;   // 将现在textBox的值保存下来
            //    }
            //}


        }

   
}
